package server.controller;

import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.Broadcaster;
import l1j.server.server.model.L1World;
import l1j.server.server.model.Instance.L1DollInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_SkillSound;

public class DollHpMpRegenController extends TimerTask{
	private static Logger _log = Logger.getLogger(DollHpMpRegenController.class.getName());
	private static Timer _dollHpMpTimer = new Timer();
	private final int _regenTime;
	public DollHpMpRegenController(int regenTime) { _regenTime = regenTime; }

	public void start() { _dollHpMpTimer.scheduleAtFixedRate(DollHpMpRegenController.this, _regenTime, _regenTime); }
	
	@Override
	public void run(){ }
	public void regenMp(L1PcInstance _pc) {
		int regenMp = 0; 
		
		for (L1DollInstance doll : _pc.getDollList().values()) { regenMp = doll.getMpRegenerationValues(); }
		int newMp = _pc.getCurrentMp() + regenMp;

		_pc.setCurrentMp(newMp);
		_pc.sendPackets(new S_SkillSound(_pc.getId(), 6321)); 
		Broadcaster.broadcastPacket(_pc, new S_SkillSound(_pc.getId(), 6321));

	}
	
	public void regenHp(L1PcInstance _pc) {

		int newHp = _pc.getCurrentHp() + 40;
		if (newHp < 0) { newHp = 0; }
		_pc.setCurrentHp(newHp);
		_pc.sendPackets(new S_SkillSound(_pc.getId(), 1608)); 
		Broadcaster.broadcastPacket(_pc, new S_SkillSound(_pc.getId(), 1608));
	}
}
